package com.zx.dsptuneup_cloud;

import android.app.Application;

import com.hjq.toast.ToastUtils;
import com.orhanobut.hawk.Hawk;
import com.zx.dsptuneup_cloud.Data_Bean.EQBean;
import com.zx.dsptuneup_cloud.ProtocolTools.Config;
import com.zx.dsptuneup_cloud.Tools.ProtocolServiceUtil;
import com.zx.dsptuneup_cloud.Util.Constants;
import com.zx.dsptuneup_cloud.ProtocolTools.ProtocolConversion;
import com.zx.dsptuneup_cloud.Util.Netty.NettyClient;
import com.zx.dsptuneup_cloud.Util.UserUtil;

public class App extends Application {
    private static final String TAG = "App";

    private static App mContext;
    private static EQBean eqData;    // 存储的EQ数据

    private NettyClient nettyClient;//socket操作连接对象
 private ProtocolConversion protocolConversion ;
    private ProtocolServiceUtil protocolServiceUtil;

    public ProtocolServiceUtil getProtocolServiceUtil() {
        return protocolServiceUtil;
    }

    public void setProtocolServiceUtil(ProtocolServiceUtil protocolServiceUtil) {
        this.protocolServiceUtil = protocolServiceUtil;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
        eqData = new EQBean();
//        nettyClient = new NettyClient(Constants.HOST, Constants.TCP_PORT);
        protocolConversion = new ProtocolConversion();
        protocolServiceUtil=new ProtocolServiceUtil();
        ToastUtils.init(this);
        Hawk.init(this).build();

        // 是否开发者
        if(Hawk.contains(UserUtil.DevelopMode) ){
            boolean flag = Hawk.get(UserUtil.DevelopMode);
            UserUtil.isDevelopMode = flag ? true : false;
        }

        // 初始化数据结构
        Config.configData();

        // 输入通道14段
//        for (int i=0;i<14;i++) {
//            ChanelBean chanelBean = new ChanelBean();
//            for (int j=0;j<15;j++) {
//                EqSegmentBean eqSegmentBean = new EqSegmentBean(freqArr[j] + "", 0, 1.41);
//                chanelBean.getEqSegArr().add(eqSegmentBean);
//            }
//            chanelBean.setHighCut(20000);
//            chanelBean.setLowCut(20);
//            chanelBean.setMute(true);
//            chanelBean.setVolume(0);
//            eqData.getInputChannelArr().add(chanelBean);
//        }

//        String jsonStr = new Gson().toJson(App.getEqData());
//        Log.e("eqBean","eqBean===="+jsonStr);

    }

    public void reinitSocket(){
        nettyClient = new NettyClient(Constants.HOST, Constants.TCP_PORT);
    }

    public ProtocolConversion getProtocolConversion() {
        return protocolConversion;
    }

    public NettyClient getNettyClient() {
        return nettyClient;
    }

    public static EQBean getEqData() {
        return eqData;
    }

    public static App getContext() {
        return mContext;
    }

}
